/**
 * 
 */
package cci.rodez.iiil.random.generator;

import java.util.ArrayList;

import JSci.maths.statistics.PoissonDistribution;

/**
 * @author g.grezes
 *
 */
public class LoiPoisson extends Generator {
	
	private Double alpha = 4.0;
	
	public LoiPoisson() {
		min = 0.0;
		max = 2000.0;
		nbParametre = 1;
		nomLoi = "de Poisson";
	}
	
	public LoiPoisson(Double alpha) {
		this();
		this.alpha = alpha;
	}

	/* (non-Javadoc)
	 * @see cci.rodez.iiil.random.generator.Generator#generateEvent(int)
	 */
	@Override
	public ArrayList<Double> generateEvent(int nbEvent) {
		Double s = alpha;
		Double r = -1.0;
		
		ArrayList<Double> resultFinal = new ArrayList<Double>();
		
		for (int i = 0; i < nbEvent; i++) {
			s = alpha;
			r = -1.0;
			while (s >= 0) {
				r++;
				//s += Math.log(1-Math.random());
				s += (-1/alpha)*Math.log(Math.random());
			}
			resultFinal.add(r);
		}
		
		return resultFinal;
	}

	/* (non-Javadoc)
	 * @see cci.rodez.iiil.random.generator.Generator#getYTheoric(java.lang.Double)
	 */
	@Override
	public Double getYTheoric(Double xEvent) {
		PoissonDistribution poisson = new PoissonDistribution(alpha);
		return poisson.cumulative(xEvent);
	}
	
	public Double getYProbaTheoric(Double xEvent) {
		PoissonDistribution poisson = new PoissonDistribution(alpha);
		return poisson.probability(xEvent);
	}
	
	@Override
	public Boolean isDiscrete() {
		return true;
	}

}
